package site.shihuan.helpdesk.common.amqp.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * RabbitConfig.
 *
 * @author 周世焕
 * @Date 2021/3/11 14:15
 */
@Configuration
public class AmqpConfig {

    @Bean
    public Queue queueChatOneToOne() {
        return new Queue(AmqpQueue.CHAT_ONE_TO_ONE);
    }

    @Bean
    public Queue queueStartService() {
        return new Queue(AmqpQueue.START_SERVICE);
    }

    @Bean
    public Queue queueFinishService() {
        return new Queue(AmqpQueue.FINISH_SERVICE);
    }

    @Bean
    DirectExchange exchangeChat() {
        return new DirectExchange(AmqpExchange.CHAT);
    }

    @Bean
    DirectExchange exchangeService() {
        return new DirectExchange(AmqpExchange.SERVICE);
    }

    @Bean
    Binding bindingQueueChatOneToOne() {
        return BindingBuilder.bind(queueChatOneToOne()).to(exchangeChat()).with(AmqpQueue.CHAT_ONE_TO_ONE);
    }

    @Bean
    Binding bindingQueueStartService() {
        return BindingBuilder.bind(queueStartService()).to(exchangeService()).with(AmqpQueue.START_SERVICE);
    }

    @Bean
    Binding bindingQueueFinishService() {
        return BindingBuilder.bind(queueFinishService()).to(exchangeService()).with(AmqpQueue.FINISH_SERVICE);
    }
}
